package org.xhy.sniffer.plugin;

import lombok.extern.slf4j.Slf4j;
import org.xhy.sniffer.loader.AgentClassLoader;

import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

/**
 * @description: 找到 skywalking-plugin.def 文件
 * @gitee: https://gitee.com/XhyQAQ
 * @copyright: B站: https://space.bilibili.com/152686439
 * @Author: Xhy
 * @CreateTime: 2024-07-11 20:23
 */
@Slf4j
public class PluginResourcesResolver {

    public List<URL> getResources() {
        List<URL> cfgUrlPaths = new ArrayList<>();
        try {
            Enumeration<URL> urls = AgentClassLoader.getDefault().getResources("skywalking-plugin.def");
            while (urls.hasMoreElements()) {
                URL pluginDefineDefUrl = urls.nextElement();
                cfgUrlPaths.add(pluginDefineDefUrl);
                log.info("find skywalking plugin define file url :{}",pluginDefineDefUrl);
            }
            return cfgUrlPaths;
        }catch (Exception e) {
            log.error("read resource error",e);
        }
        return null;
    }

}
